home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / bs941029.tgz / bbsx-941029.tar / bbsx / mkboxpwd.c < prev    next >
C/C++ Source or Header  |  1994-10-29  |  1KB  |  49 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <ctype.h>
  5. #include <unistd.h>
  6. #include <string.h>
  7.  
  8. main(int argc, char **argv)
  9. {
  10.   FILE *fp;
  11.   char *filename;
  12.   unsigned int c;
  13.   time_t t;
  14.   int writetofile = 0;
  15.   int i;
  16.   
  17.   while ((c = getopt(argc, argv, "o:")) != EOF) {
  18.     switch (c) {
  19.       case 'o':
  20.         writetofile = 1;
  21.         filename = strdup(optarg);
  22.         break;
  23.       default:
  24.         printf("usage: mkboxpwd [-o outputfile]\n");
  25.         exit (1);
  26.     }      
  27.   }
  28.   srand((unsigned) time(&t));
  29.   if (writetofile) {
  30.     if ((fp = fopen(filename,"w")) == NULL) {
  31.        printf("can not open: %s\n", filename);
  32.        exit (1);
  33.     }
  34.   }
  35.   for (i=0; i < 1620; i++) {
  36.     do {
  37.       c = (char) random();
  38.       if (isalnum(c) && (c < 127)) {
  39.           fputc(c, writetofile ? fp : stdout);
  40. /*          if (!((i+1) % 27))
  41.             fputc('\n', writetofile ? fp : stdout); */
  42.       }      
  43.     } while (!isalnum(c) || (c >= 127));
  44.   }
  45.   if (writetofile) {
  46.      fclose(fp);
  47.      chmod(filename,0600);
  48.   }               
  49. }